<extend name="./public/frame.html"/>
<block name="content">
    <style type="text/css">
        blockquote {
            -webkit-margin-end: 0px;
        }
    </style>
    <div class="layui-collapse">
    <if condition="in_array($info['status'],array(0,30,35))">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">订单分派</h2>
            <div class="layui-colla-content layui-show">
                <blockquote class="layui-elem-quote search">
                    <div class="layui-inline">
                        <!--<div class="layui-input-inline">-->
                            <!--<select lay-verify="required" lay-search="" id="driver">-->
                                <!--<option value="">请选择司机</option>-->
                                <!--<option value="cancel">取消分配</option>-->
                                <!--<eq name="info['order_status']" value="已付款">-->
                                    <!--<volist name="distance" id="dis">-->
                                        <!--<option value="{$driver_infos[$key]['driver_id']}">{$driver_infos[$key]['car_plate']}-{$driver_infos[$key]['driver_name']}-{$driver_infos[$key]['work_area']}-({$driver_infos[$key]['allot_count']}/{$driver_infos[$key]['seats']})-距离{$dis/1000}公里</option>-->
                                    <!--</volist>-->
                                    <!--<else/>-->
                                    <!--<volist name="driver_infos" id="driver_info">-->
                                        <!--<option value="{$driver_info['driver_id']}">{$driver_info['car_plate']}-{$driver_info['driver_name']}-{$driver_info['work_area']}-({$driver_info['allot_count']}/{$driver_info['seats']})</option>-->
                                    <!--</volist>-->
                                <!--</eq>-->
                            <!--</select>-->
                        <!--</div>-->
                        <div class="layui-input-inline">
                        <input type="text" name="driver_name" lay-verify="required|name" required placeholder="司机姓名" class="layui-input" id="driver_name">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="driver_phone" lay-verify="required|number" required placeholder="手机号码" class="layui-input" id="driver_phone">
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" data-type="search">搜索</button>
                            <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
                        </div>
                    </div>
                </blockquote>
                <table class="layui-table" id="memberList" lay-filter="memberList">

                </table>
                <script type="text/html" id="barDemo">
                    <if condition="$info['driver_id'] neq ''">
                        {{#if(d.car_id == {$info['car_id']}) {}}
                        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cancel">取消分配</a>
                        {{#}else{}}
                        <a class="layui-btn layui-btn-xs" lay-event="allot">派给TA</a>
                        {{#}}}
                    <else />
                        <a class="layui-btn layui-btn-xs" lay-event="allot">派给TA</a>
                    </if>
                </script>
                <script type="application/javascript">
                    layui.use(['table'], function () {
                        var table = layui.table;

                        var tableIns = table.render({
                            elem:"#memberList",
                            url:"{$driver_url}",
                            cols: [[
                                {title:"司机ID",field:'driver_id', width:'100',align:'center'},
                                {title:"司机姓名",field:'driver_name',width:'200',align:'center'},
                                {title:"已占座/总座位数",field:'seat_num',width:'200',align:'center'},
                                {title:"车牌号",field:'car_plate',width:'200',align:'center'},
                                {title:"手机号",field:'driver_phone',width:'200',align:'center'},
                                {title:"距离该订单起点位置",field:'dis',width:'200',align:'center'},
                                {title:"操作",toolbar: '#barDemo',width:180,align:'center'}
                            ]],
                            page:true,
                            limit:10,
                            done: function(res, curr, count){
                                _cur_page = curr;
                                _cur_limit = res['limit'];
                                _count = count;
                            }
                        });

                        //监听工具条
                        table.on('tool(memberList)', function (obj) {
                            var data = obj.data; //获得当前行数据
                            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                            var tr = obj.tr; //获得当前行 tr 的DOM对象
                            var id = data.id;
                            var driver_id = data.driver_id;
                            if (layEvent === 'allot') {
                                if(driver_id!=''){
                                    $('.fadeBg').show();
                                    $('.fadeCont .upload').show();
                                    $('.fadeCont').show();
                                    var common_id = "{$info['id']}";
                                    $.post('{$url}',{driver_id:driver_id,common_id:common_id},function (res) {
                                        $('.fadeBg').hide();
                                        $('.fadeCont .upload').hide();
                                        $('.fadeCont').hide();
                                        switch (res['status']){
                                            case 1:
                                                layer.alert(res['msg'],{icon: 6}, function(index){
                                                    window.location.reload();
                                                });
                                                break;
                                            default:
                                                layer.alert(res['msg'],{icon: 5});
                                                break;
                                        }
                                    },'json');
                                }else{
                                    layer.alert('请选择司机');
                                }
                            } else if (layEvent === 'cancel') {  //取消订单
                                if(driver_id!=''){
                                    $('.fadeBg').show();
                                    $('.fadeCont .upload').show();
                                    $('.fadeCont').show();
                                    var common_id = "{$info['id']}";
                                    $.post('{$url}',{driver_id:'cancel',common_id:common_id},function (res) {
                                        $('.fadeBg').hide();
                                        $('.fadeCont .upload').hide();
                                        $('.fadeCont').hide();
                                        switch (res['status']){
                                            case 1:
                                                layer.alert(res['msg'],{icon: 6}, function(index){
                                                    window.location.reload();
                                                });
                                                break;
                                            default:
                                                layer.alert(res['msg'],{icon: 5});
                                                break;
                                        }
                                    },'json');
                                }else{
                                    layer.alert('请选择司机');
                                }
                            }
                        });

                        var $ = layui.jquery, active = {
                            search: function () {
                                var driver_phone = $.trim($("#driver_phone").val()),
                                    driver_name = $.trim($("#driver_name").val());
                                var reset = $('#reset');
                                if (driver_phone || driver_name) {
                                reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                                    tableIns.reload({
                                        url: '{$driver_url}',
                                        where: {
                                            "driver_phone":driver_phone,
                                            "driver_name":driver_name
                                        } //设定异步数据接口的额外参数
                                    });
                                } else {
                                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                                    alert('搜索项不能为空');
                                }
                            }
                            , reset: function () {
                                var reset = $('#reset');
                                if (reset.data('type') !== '') {
                                    tableIns.reload({
                                        url: '{$driver_url}',where:{}
                                    });
                                }
                                $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                                reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                            }
                        };

                        $('.layui-btn').on('click', function () {
                            var type = $(this).data('type');
                            active[type] ? active[type].call(this) : '';
                        });

                    });

                </script>
            </div>
        </div>
    </if>
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">订单详情</h2>
        <div class="layui-colla-content layui-show" style="overflow: hidden;">
            <form class="layui-form" action="{$url}" method="post">
                <table class="layui-table" style="width:49%; float:left;">
                    <volist name="fields" id="field" key="keyNum">
                        <if condition="!in_array($key,$ipt)">
                            <tr>
                                <if condition="$keyNum%2 neq 0">
                                    <td style="text-align: center">{$keyNum}.{$field}：</td>
                                    <if condition="$key=='order_status'">
                                        <td style="color:{$color}">{$info[$key]}</td>
                                        <elseif condition="$key=='journey' OR $key=='dis'"/>
                                        <td>{$info[$key]/1000}公里</td>
                                        <else/>
                                        <td>{$info[$key]}</td>
                                    </if>
                                </if>
                            </tr>
                        </if>
                    </volist>
                </table>
                <table class="layui-table" style="width:49%;float: right;">
                    <volist name="fields" id="field" key="keyNum">
                        <tr>
                                <if condition="$keyNum%2 eq 0">
                                    <td style="text-align: center">{$keyNum}.{$field}：</td>
                                    <if condition="$key=='order_status'">
                                        <td style="color:{$color}">{$info[$key]}</td>
                                        <elseif condition="$key=='journey' OR $key=='dis'"/>
                                        <td>{$info[$key]/1000}公里</td>
                                        <else/>
                                        <td>{$info[$key]}</td>
                                    </if>
                                </if>
                            </tr>
                    </volist>
                </table>
            </form>
        </div>
    </div>

    <div class="layui-colla-item">
        <h2 class="layui-colla-title">费用明细</h2>
        <div class="layui-colla-content layui-show" style="overflow: hidden;">
            <form class="layui-form" action="{$url}" method="post">
                <table class="layui-table" style="width:49%;float:left;">
                    <volist name="fee_info" id="fee" key="keyNum">
                        <if condition="!in_array($key,$ipt)">
                            <tr>
                                <if condition="$keyNum%2 neq 0">
                                    <td style="text-align: center">{$keyNum}.{$fee}：</td>
                                    <td>{$info[$key]}</td>
                                </if>
                            </tr>
                        </if>
                    </volist>
                </table>
                <table class="layui-table" style="width:49%;float: right;">
                    <volist name="fee_info" id="fee" key="keyNum">
                        <!--<if condition="!in_array($key,$ipt)">-->
                            <tr>
                                <if condition="$keyNum%2 eq 0">
                                    <td style="text-align: center">{$keyNum}.{$fee}：</td>
                                    <td>{$info[$key]}</td>
                                </if>
                            </tr>
                        <!--</if>-->
                    </volist>
                </table>
            </form>
        </div>
    </div>
<if condition="$info['status'] eq 50">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">评价信息</h2>
        <div class="layui-colla-content layui-show" style="overflow: hidden;">
            <form class="layui-form" action="{$url}" method="post">
                <table class="layui-table" style="width:49%;float:left;">
                    <volist name="comment_info" id="comment" key="keyNum">
                        <if condition="!in_array($key,$ipt)">
                            <tr>
                                <if condition="$keyNum%2 neq 0">
                                    <td style="text-align: center">{$keyNum}.{$comment}：</td>
                                    <td>{$info[$key]}</td>
                                </if>
                            </tr>
                        </if>
                    </volist>
                </table>
                <table class="layui-table" style="width:49%;float: right;">
                    <volist name="comment_info" id="comment" key="keyNum">
                        <if condition="!in_array($key,$ipt)">
                            <tr>
                                <if condition="$keyNum%2 eq 0">
                                    <td style="text-align: center">{$keyNum}.{$comment}：</td>
                                    <td>{$info[$key]}</td>
                                </if>
                            </tr>
                        </if>
                    </volist>
                </table>
            </form>
        </div>
    </div>
</if>
    <if condition="in_array($info['status'],array(30,35))">
        <div class="fadeBg"></div>
        <div class="fadeCont" style="width: 20%;left: 40%;top: 30%">
            <div class="fadeBox upload">
                <img src="__WEB__/images/uploading.gif" style="width: 30%;height: auto">
                <p style="font-size: 12px;margin-bottom: 3px;">处理中，请稍等……</p>
            </div>
        </div>
        <script type="application/javascript">
            layui.use([ 'laytpl', 'laydate','form','element'], function () {
                var form = layui.form
                    , laydate = layui.laydate
                    , element = layui.element;
                var $ = layui.jquery, active = {
//                    allot: function () {
//                        var driver = $('#driver').val();
//                        if(driver!=''){
//                            $('.fadeBg').show();
//                            $('.fadeCont .upload').show();
//                            $('.fadeCont').show();
//                            var common_id = "{$info['id']}";
//                            $.post('{$url}',{driver_id:driver,common_id:common_id},function (res) {
//                                $('.fadeBg').hide();
//                                $('.fadeCont .upload').hide();
//                                $('.fadeCont').hide();
//                                switch (res['status']){
//                                    case 1:
//                                        layer.alert(res['msg'],{icon: 6}, function(index){
//                                            window.location.reload();
//                                        });
//                                        break;
//                                    default:
//                                        layer.alert(res['msg'],{icon: 5});
//                                        break;
//                                }
//                            },'json');
//                        }else{
//                            layer.alert('请选择司机');
//                        }
//                    }
//                    , reset: function () {
//                        var reset = $('#reset');
//                        if (reset.data('type') !== '') {
//                            table.reload('order', {
//                                url: '/admin/inter_order/table',where:{}
//                            });
//                        }
//                        $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
//                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
//                    }
                };
//                $('.layui-btn').on('click', function () {
//                    var type = $(this).data('type');
//                    active[type] ? active[type].call(this) : '';
//                });
            });
        </script>
    </if>

    </div>
</block>
